#include "StdAfx.h"
#include "BaseLayer.h"
#include "Packet.h"

#define MaxAdapterObjects 10
class CNILayer
	:public CBaseLayer, public CPacket
{
public:
	CNILayer(char* pName,  int iNumAdapter = 0);
	CNILayer();

	pcap_if_t* GetAdapterObject(int iIndex);
	char* GetAdapterList_des(int iIndex);
	char* GetAdpaterList(char iIndex);
	UCHAR* GetAdapterAddrList(int iIndex);
	int GetAdapterNum();
	pcap_t* GetSelectedDevs();

	BOOL PacketGetAddress( PUCHAR AddressBuffer); 
	void SetAdapterNumber(int iNum);
	void SetAdapterList();
	void SetSelectedDevs(pcap_t *);
	void SetSelectedAdapterNum(int num);
	void ResetData();
	void SetAdapterAddrList();
	//BOOL PacketGetAddress(LPADAPTER AdapterObject, PUCHAR AddressBuffer);
	BOOL Receive();
	BOOL Send(unsigned char* pPayload, int nlength);

	BOOL SendPacket(pcap_t* selectedDevs, UCHAR* SendBuffer);
	BOOL ReceivePacket(pcap_t* selectedDevs, const u_char* ReceiveBuffer);

	static UINT ReadingThread(LPVOID );
	static UINT FileSendThread(LPVOID);
	static UINT FileReceiveThread(LPVOID);
	static UINT WritingThread(LPVOID);
	virtual ~CNILayer();

	CWinThread* m_pReadingThread;
	CWinThread* m_pWritingThread;
	CWinThread* m_pFileSendThread;
	CWinThread* m_pFileReceiveThread;

	BOOL m_DlgSet;

private:
	char        m_AdapterList[10][1024];
	char		m_AdapterList_descript[10][1024];
	char		m_AdapterName[8192];
	UCHAR m_AdapterAddrList[10][6];
	
	int m_AdapterNum;
	int m_SelectedAdatperNum;
	
	pcap_if_t *alldevs;
	pcap_if_t *devices[MAXDEVICENUM];
	pcap_t * selectedDevs;
	struct pcap_pkthdr *hdr;
	UCHAR SendBuffer[ETHER_MAX_SIZE];
	const u_char *ReceiveBuffer;

	UCHAR FileSendBuffer[ETHER_MAX_SIZE];
	const u_char *FileReceiveBuffer;
	

};